package com.javasm.shop;

import java.util.ArrayList;
import java.util.Scanner;

public class Shop {
    public static void main(String[] args) {
        //创建一个水果集合
        ArrayList<FruitItem> array = new ArrayList<FruitItem>();
        //调用商品初始方法，传递商品
        init(array);
        //创建一个循环，一直运行的东西
        while(true){
            mainMenu();
            //根据客户的选项来选择自己想要的商品
            int  num = chooseFunction();
            switch (num){
                case 1:
                    showFruitList(array);
                    break;
                case 2:
                    addFruit(array);
                    break;
                case 3:
                    showFruitList(array);
                    deleteFruit(array);
                    break;
                case 4:
                    showFruitList(array);
                    upDateFruitList(array);
                    break;
                case 5:
                    quit(array);
                    return;
                default:
                    System.out.println("您输入的序列号不在列表内");
                    break;

            }



        }
    }

    private static void quit(ArrayList<FruitItem> array) {
        System.out.println("您已经退出系统，请再次使用");

    }

    private static void upDateFruitList(ArrayList<FruitItem> array) {



    }

    private static void deleteFruit(ArrayList<FruitItem> array) {
        System.out.println("你输入的是删除的功能");
        System.out.println("请您输入商品的编号");
            Scanner sc =new Scanner(System.in);
            int ID = sc.nextInt();
        for (int i = 0; i < array.size(); i++) {
                FruitItem  it = array.get(i);
                if(it.ID ==  ID){
                    array.remove(i);
                    System.out.println("删除陈工");
                    return;
                }


        }

        
    }

    private static void addFruit(ArrayList<FruitItem> array) {
        System.out.println("您选择的是商品添加功能");
        Scanner sc = new Scanner(System.in);
        System.out.println("请您输入商品的编号");
        int  ID  = sc.nextInt();
        System.out.println("请您输入商品的名字");
        String  name = sc.next();
        System.out.println("请您输入商品的价格");
        int  price = sc.nextInt();
        while (price <0){
            System.out.println("您输入的价格不合法，请重新输入");
            price = sc.nextInt();
        }

        FruitItem it =new FruitItem();
        it.ID = ID;
        it.name = name;
        it.price = price;
        array.add(it);


    }

    private static void showFruitList(ArrayList<FruitItem> array) {

        System.out.println();
        System.out.println("----商品库存清单----------");
        System.out.println("商品编号"+"商品名称"+"商品单价");
        for (int i = 0; i < array.size(); i++) {
            FruitItem   it = array.get(i);
            System.out.println(it.ID + it.name +it.price);
        }
    }

    private static int chooseFunction() {

        Scanner sc = new Scanner(System.in);
        return sc.nextInt();

    }

    private static void mainMenu() {
        System.out.println();
        System.out.println("欢迎光临库存管理系统");
        System.out.println("1.货物清单");
        System.out.println("2.添加货物");
        System.out.println("3.修改货物");
        System.out.println("4.删除货物");
        System.out.println("5.退出系统！！！");
        System.out.println("请输入您选择的编号内容-------------------------");

    }

    private static void init(ArrayList<FruitItem> array) {
            //创建多个集合属性，并且给属性赋值
        FruitItem f1 = new FruitItem();
        f1.ID = 10086;
        f1.name = "苹果";
        f1.price = 10 ;

        FruitItem f2 = new FruitItem();
        f2.ID =10087;
        f2.name = "水蜜桃";
        f2.price = 15;

        FruitItem  f3 = new FruitItem();
        f3.ID = 1002154;
        f3.name = "香蕉";
        f3.price  =  18;

        array.add(f1);
        array.add(f2);
        array.add(f3);



    }

}
